// -----------------------------------------------
// Author:     code34 nicolas_boiteux@yahoo.fr
// Edited by:  Neumatic
// Warcontext; Nasty thing happen to vehicle after sabotage
// -----------------------------------------------

private ["_unit","_sabotage"];

_unit = _this select 0;

_sabotage = ["fuel", "explosion", "weapon", "sabotage", "speed", "ied"] call BIS_fnc_selectRandom;

switch (_sabotage) do {
	case "fuel": {
		_unit setVariable ["typeofsabotage", "fuel", false];
		_unit setDamage 0.05;
		while {damage _unit > 0} do {
			if (speed _unit > 1) then {
				if (count (crew _unit) > 0) then {
					_unit setFuel ((fuel _unit) - 0.05);
				};
			};
			sleep 1;
		};

		//A3 TODO: setVehicleInit
		_unit setVehicleInit "this setDamage 1; this vehicleChat ""VEHICLE WAS SABOTAGED"";";
		processInitCommands;
	};

	case "explosion": {
		_unit setVariable ["typeofsabotage", "explosion", false];
		while {alive _unit} do {
			if (count (crew _unit) > 2) then {
				if (speed _unit > (30 + random 30)) then {
					{
						_x setDamage (0.9 + (random 0.5));
					} foreach crew _unit;

					//A3 TODO: setVehicleInit
					_unit setVehicleInit "this setDamage 1; this vehicleChat ""VEHICLE WAS SABOTAGED"";";
					processInitCommands;
				};
			};
			sleep 1;
		};
	};

	//A3 TODO: setVehicleInit
	case "weapon": {
		_unit setVariable ["typeofsabotage", "ammo", false];
		_unit setVehicleInit "this setVehicleAmmo 0;";
		processInitCommands;
	};

	//A3 TODO: setVehicleInit
	case "sabotage" : {
		_unit setVariable ["typeofsabotage", "sabotage", false];
		_unit setVehicleInit "this setDamage 0.95;";
		processInitCommands;
	};

	case "ied" : {
		_unit setVariable ["typeofsabotage", "ied", false];
		wcgarbage = [_unit] spawn WC_fnc_createied;
	};
};